package ejbcareader.reader.pojo;

import java.math.BigInteger;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CertificatePojo {
	
	public CertificatePojo(X509Certificate x509Certificate, Boolean isRevoked, int keySize){		
		
		setSerial(x509Certificate.getSerialNumber());
		setIssueDate(x509Certificate.getNotAfter());
		setExpirationDate(x509Certificate.getNotBefore());
		
		setKeySize(keySize);
		setIsRevoked(isRevoked);
		
		setDistinguishedName(x509Certificate.getSubjectDN().getName());		
	}

	private BigInteger serial;
	
	private Date issueDate;
	
	private Date expirationDate;
	
	private int keySize;
	
	private Boolean isRevoked;
	
	private String distinguishedName;

	public BigInteger getSerial() {
		return serial;
	}

	public void setSerial(BigInteger serial) {
		this.serial = serial;
	}

	public Date getIssueDate() {
		return issueDate;
	}

	public void setIssueDate(Date issueDate) {
		this.issueDate = issueDate;
	}

	public Date getExpirationDate() {
		return expirationDate;
	}

	public void setExpirationDate(Date expirationDate) {
		this.expirationDate = expirationDate;
	}

	public int getKeySize() {
		return keySize;
	}

	public void setKeySize(int keySize) {
		this.keySize = keySize;
	}

	public Boolean getIsRevoked() {
		return isRevoked;
	}

	public void setIsRevoked(Boolean isRevoked) {
		this.isRevoked = isRevoked;
	}

	public String getDistinguishedName() {
		return distinguishedName;
	}

	public void setDistinguishedName(String distinguishedName) {
		this.distinguishedName = distinguishedName;
	}
	
	public String toString()
	{			
		char sepChar = (int)9;
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy H:mm");
				
		StringBuffer buffer = new StringBuffer();
		buffer.append(getSerial());
		buffer.append(sepChar);
		buffer.append(formatter.format(getIssueDate()));
		buffer.append(sepChar);
		buffer.append(formatter.format(getExpirationDate()));
		buffer.append(sepChar);		
		buffer.append(getKeySize());
		buffer.append(sepChar);		
		buffer.append(getIsRevoked());
		buffer.append(sepChar);		
		buffer.append(getDistinguishedName());
		buffer.append(sepChar);		
		
		return buffer.toString();		
	}
}
